"""
Author        yongfa
Date          2023-08-31 03:37:44
LastEditTime  2023-09-05 09:37:23
LastEditors   yongfa
Description   路由
"""

from flask_restx import Resource

from app.extensions.decorators import header_required, casbin_required
from .models import EmailInfo, ResumeEmailTask, ResumeEmail, ResumeParserTask, ResumeContent
from .parameters import set_params
from .services import EmailInfoService, ResumeEmailTaskService, ResumeEmailService, \
    ResumeParserTaskService, ResumeContentService


def configure_router(ns):
    @ns.route("/emailInfo")
    class EmailInfoListResource(Resource):
        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['get_list_params'], description="获取邮箱信息列表")
        @ns.expect(set_params['get_list_params'])
        def get(self):
            """获取邮箱信息列表"""
            return EmailInfoService(model=EmailInfo,
                                    args=set_params['get_list_params'], filter_delete=True).get_list()

    @ns.route("/emailInfo/<int:id>")
    @ns.doc(params={"id": "邮箱信息id"})
    class EmailInfoDetailResource(Resource):
        method_decorators = [header_required]

        def get(self, id):
            """获取邮箱信息详情"""
            return EmailInfoService(model=EmailInfo, args=None, filter_delete=True).get_detail(id)

    @ns.route("/emailTask")
    class ResumeEmailTaskListResource(Resource):
        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['get_list_ret_params'], description="获取邮箱任务列表")
        @ns.expect(set_params['get_list_ret_params'])
        def get(self):
            """获取邮箱任务列表"""
            return ResumeEmailTaskService(model=ResumeEmailTask,
                                          args=set_params['get_list_ret_params'],
                                          filter_delete=True, is_desc=True).get_list()

        @ns.doc(parser=set_params['create_ret_params'], description="添加邮箱任务")
        @ns.expect(set_params['create_ret_params'])
        def post(self):
            """添加邮箱任务"""
            return ResumeEmailTaskService(model=ResumeEmailTask,
                                          args=set_params['create_ret_params'], filter_delete=True).create()

    @ns.route("/emailTask/<int:id>")
    @ns.doc(params={"id": "邮箱任务ID"})
    class ResumeEmailTaskDetailResource(Resource):
        method_decorators = [header_required]

        def get(self, id):
            """获取邮箱任务详情"""
            return ResumeEmailTaskService(model=ResumeEmailTask, args=None, filter_delete=True).get_detail(id)

    @ns.route("/emailTask/checkLogin")
    class ResumeEmailTaskCheckLoginResource(Resource):

        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['create_ret_params'], description="检查邮箱登录信息")
        @ns.expect(set_params['create_ret_params'])
        def post(self):
            """检查邮箱登录信息"""
            return ResumeEmailTaskService(model=ResumeEmailTask,
                                          args=set_params['create_ret_params'], filter_delete=True).check_email_login()

    @ns.route("/emailTask/testPull")
    class ResumeEmailTaskTestPullResource(Resource):

        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['create_ret_params'], description="测试邮箱读取邮件")
        @ns.expect(set_params['create_ret_params'])
        def post(self):
            """测试邮箱读取邮件"""
            return ResumeEmailTaskService(model=ResumeEmailTask,
                                          args=set_params['create_ret_params'], filter_delete=True).test_pull_email()

    @ns.route("/email")
    class ResumeEmailListResource(Resource):
        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['get_list_re_params'], description="获取邮件列表")
        @ns.expect(set_params['get_list_re_params'])
        def get(self):
            """获取邮件列表"""
            return ResumeEmailService(model=ResumeEmail,
                                      args=set_params['get_list_re_params'],
                                      filter_delete=True, is_desc=True).get_list()

    @ns.route("/email/<int:id>")
    @ns.doc(params={"id": "邮件信息id"})
    class ResumeEmailDetailResource(Resource):
        method_decorators = [header_required]

        def get(self, id):
            """获取邮件信息详情"""
            return ResumeEmailService(model=ResumeEmail, args=None, filter_delete=True).get_detail(id)

    @ns.route("/parserTask")
    class ResumeParserTaskListResource(Resource):
        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['get_list_rpt_params'], description="获取简历解析任务列表")
        @ns.expect(set_params['get_list_rpt_params'])
        def get(self):
            """获取简历解析任务列表"""
            return ResumeParserTaskService(model=ResumeParserTask,
                                           args=set_params['get_list_rpt_params'],
                                           filter_delete=True, is_desc=True).get_list()

        @ns.doc(parser=set_params['create_rpt_params'], description="添加简历解析任务")
        def post(self):
            """添加简历解析任务"""
            return ResumeParserTaskService(model=ResumeParserTask,
                                           args=set_params['create_rpt_params'], filter_delete=True).create()

    @ns.route("/parserTask/<int:id>")
    @ns.doc(params={"id": "简历解析任务信息id"})
    class ResumeParserTaskDetailResource(Resource):
        method_decorators = [header_required]

        def get(self, id):
            """获取简历解析任务信息详情"""
            return ResumeParserTaskService(model=ResumeParserTask, args=None, filter_delete=True).get_detail(id)

    @ns.route("/content")
    class ResumeContentListResource(Resource):
        method_decorators = [casbin_required]

        @ns.doc(parser=set_params['get_list_rc_params'], description="获取简历解析内容列表")
        @ns.expect(set_params['get_list_rc_params'])
        def get(self):
            """获取简历解析内容列表"""
            return ResumeContentService(model=ResumeContent,
                                        args=set_params['get_list_rc_params'],
                                        filter_delete=True, is_desc=True).get_list()

    @ns.route("/content/<int:id>")
    @ns.doc(params={"id": "简历解析内容信息id"})
    class ResumeContentDetailResource(Resource):
        method_decorators = [header_required]

        def get(self, id):
            """获取简历解析内容信息详情"""
            return ResumeContentService(model=ResumeContent, args=None, filter_delete=True).get_detail(id)
